package org.mmtk.plan.colormark;

import org.mmtk.utility.Log;
import org.vmmagic.pragma.Uninterruptible;
import org.vmmagic.unboxed.ObjectReference;
import org.vmmagic.unboxed.ObjectReferenceArray;

@Uninterruptible  
class MiscUtils {
	
	public static void zeroArray(long[] array) {
		int size = array.length;
		for(int i = 0; i < size; i++) {
			array[i] = 0;
		}
	}
	
	public static void zeroArray(int[] array) {
		int size = array.length;
		for(int i = 0; i < size; i++) {
			array[i] = 0;
		}
	}
	
	public static void zeroArray(ObjectReferenceArray array) {
		int size = array.length();
		for (int i = 0; i < size; i++) {
			array.set(i, ObjectReference.nullReference());
		}
	}
	
	public static void dumpArray(ObjectReferenceArray array) {
		int size = array.length();
		Log.write("[ ");
		for (int i = 0; i < size; i++) {
			Log.write(i);
			Log.write(": ");
			Log.write(array.get(i));
			Log.write(" ");
		}
		Log.write("]");
	}
	
	public static void zeroArray(long[] array, int from, int to) {
		for(int i = from; i < to; i++) {
			array[i] = 0;
		}
	}
	
	public static void zeroArray(int[] array, int from, int to) {
		for(int i = from; i < to; i++) {
			array[i] = 0;
		}
	}
	
	public static void zeroArray(ObjectReferenceArray array, int from, int to) {
		for(int i = from; i < to; i++) {
			array.set(i, ObjectReference.nullReference());
		}
	}
}
